﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using BusinessObjects.BO_GetObjects;

public partial class Pages_ServiceRegister : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadProvince();
            LoadSidebarModule();
        }
    }

    protected void loadProvince()
    {
        try
        {
            DataTable objDT = BO_Regions.SearchByParent(0);
            for (int i = 0; i < objDT.Rows.Count; i++)
            {
                ddlProvince.Items.Add(new ListItem(objDT.Rows[i]["REGION_NAME_VN"].ToString(), objDT.Rows[i]["REGION_ID"].ToString()));
                loadProvince(objDT.Rows[i]["REGION_ID"].ToString(), "");
            }
        }
        catch (Exception ex)
        {

            throw;
        }
    }

    protected void loadProvince(string id, string append)
    {
        append += "--";
        DataTable objDT = BO_Regions.SearchByParent(Convert.ToInt32(id));
        for (int i = 0; i < objDT.Rows.Count; i++)
        {
            ddlProvince.Items.Add(new ListItem(append + objDT.Rows[i]["REGION_NAME_VN"].ToString(), objDT.Rows[i]["REGION_ID"].ToString()));
        }
    }

    protected void Regist(object sender, EventArgs e)
    {
        string strReturn = BO_Members.Insert(Convert.ToInt32(ddlProvince.SelectedValue), O2S.O2S_Number.RamdomNumber(6), txtUsername.Value, txtPassword.Value, txtName.Value, txtAddress.Value, "", txtFone.Value, txtEmail.Value, 0, DateTime.Now, DateTime.Now, DateTime.Now, chbxEmail.Checked/*per*/, Convert.ToBoolean(Request["person"]), false, true, DateTime.Now, txtUsername.Value, DateTime.Now, txtUsername.Value, 1);
        if (strReturn != "0")
        {
            Response.Write("ok");
        }
        else
        {
            Response.Write("not ok");
        }
    }

    protected void LoadSidebarModule()
    {
        DataTable objDT = null;
        objDT = BO_Module.SelectLocation(3);
        for (int i = 0; i < objDT.Rows.Count; i++)
        {
            if (objDT.Rows[i]["type_id"].ToString() == "3")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucCustomSearch.ascx");
                Controls_ucCustomSearch control = (Controls_ucCustomSearch)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "4")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucRegistService.ascx");
                Controls_ucRegistService control = (Controls_ucRegistService)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "5")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucSupport.ascx");
                Controls_ucSupport control = (Controls_ucSupport)controls;
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "6")
            {
                UserControl controls = (UserControl)Page.LoadControl("../controls/ucAds.ascx");
                Controls_ucAds control = (Controls_ucAds)controls;
                control.Module_id = objDT.Rows[i]["MODULE_ID"].ToString();
                plHolderSidebar.Controls.Add(controls);
            }
            else if (objDT.Rows[i]["type_id"].ToString() == "7")
            {
                //UserControl controls = (UserControl)Page.LoadControl("../controls/ucRegistService.ascx");
                //Controls_ucRegistService control = (Controls_ucRegistService)controls;
                //pldHolderLeft.Controls.Add(controls);
            }
        }
    }
}